//
//  ViewController.m
//  testdemo
//
//  Created by yule on 2017/5/16.
//  Copyright © 2017年 yule. All rights reserved.
//

#import "ViewController.h"
#import "MujiDubRecorder.h"
#import "MujiDubFilePathUtility.h"
#import <lame/lame.h>
#import "MujiDubViewController.h"
#import "MujiDubPreviewViewController.h"

@interface ViewController () <MujiDubRecorderDelegate>
{
    CGFloat                         _sampleRate;

}
@property (nonatomic, assign) BOOL   recording;
@property (readwrite, nonatomic, strong)  MujiDubRecorder *dubRecorder;
@property (nonatomic, copy) NSString   *dialogId;
@property (nonatomic, copy) NSString   *dialogLineID;
@property (nonatomic, copy) NSString   *userId;

@property (nonatomic, strong) UIButton   *recordBtn;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    [self setupUI];
    
}

- (void)setupUI
{
    
    self.recordBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    
    self.recordBtn.frame = CGRectMake(100, 100, 60, 30);
    self.recordBtn.backgroundColor = [UIColor redColor];
    [self.recordBtn setTitle:@"录音" forState:UIControlStateNormal];
    
    [self.recordBtn addTarget:self action:@selector(recordBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.recordBtn];
    

    
    
    UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    
    playBtn.frame = CGRectMake(100 + 60 + 60, 100, 60, 30);
    playBtn.backgroundColor = [UIColor redColor];
    [playBtn setTitle:@"播放" forState:UIControlStateNormal];
    
    [playBtn addTarget:self action:@selector(playBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:playBtn];

}

- (void)recordBtnClicked:(UIButton *)btn
{
    
    MujiDubViewController *dubVC = [[MujiDubViewController alloc] init];
    
    dubVC.dialogId = @"20170616171911_644";
    dubVC.userId = @"1670";
    //http://img1.fancyedu.com/dubbing_sys/video/1502357593119_atxddl-szbycm？-001607-001626.mp4
    NSString *videoUrl = [NSString stringWithFormat:@"http://rongyao1.oss-cn-hangzhou.aliyuncs.com/demo/20170616171911_644.mp4"];
    dubVC.videoUrl = [videoUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
//    dubVC.imageUrl = item.picUrl;
//    dubVC.dialogTitle = item.title;
//    dubVC.duration = item.movieTime;
//    dubVC.resourceId = [NSString stringWithFormat:@"%@", item.ID];
//    dubVC.itemModel = item;
//    
//    dubVC.shareTitle = item.subTitle;
//    dubVC.shareContent = item.title;
    
    
    if (dubVC.dialogId.length == 0 || dubVC.videoUrl.length == 0) {
        return;
    }
    if (dubVC.userId.length == 0) {// 未登录  游客身份
        dubVC.userId = @"0";
    }
    
    
    [self.navigationController pushViewController:dubVC animated:YES];

    
//    MujiDubPreviewViewController *preview = [MujiDubPreviewViewController new];
//    
//    
//    [self.navigationController pushViewController:preview animated:YES];

    
}
- (void)playBtnClicked:(UIButton *)btn
{
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
